package com.wy.Service.impl;

import com.wy.Service.RoleService;
import com.wy.dao.RoleDao;
import com.wy.pojo.Role;
import com.wy.vo.PageVo;
import com.wy.vo.RoleDto;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(value="transactionManager", rollbackFor = Exception.class)
public class RoleServiceImpl extends BaseServiceImpl implements RoleService {
    @Resource
    private RoleDao roleDao;
    @Override
    public List<Role> findAll() {
        return roleDao.findAll();
    }

    @Override
    public void add(Role role) {
        roleDao.save(role);
    }

    @Override
    public void delete(Integer id) {
        roleDao.deleteById(id);
    }

    @Override
    public List<Role> findBId(Integer id) {
        return roleDao.findBId(id);
    }

    @Override
    public PageVo searchPage(Integer current, Integer pageSize, RoleDto dto) {
        StringBuilder sbd=new StringBuilder("select r from Role r  where 1=1 ");
        if(!StringUtils.isEmpty(dto.getName())){
            sbd.append(" and r.name like :name");
            dto.setName("%"+dto.getName()+"%");
        }
        return super.searchPagination(current,pageSize,sbd.toString(),dto);
    }

    @Override
    public void update(Role role) {
        roleDao.save(role);
    }
}
